﻿CREATE PROCEDURE [dbo].[sp_DeleteFile](@FileName varchar(255)) AS 
DECLARE @FS int, @OLEResult int, @FileID int 


EXECUTE @OLEResult = sp_OACreate 'Scripting.FileSystemObject', @FS OUT 
IF @OLEResult <> 0 PRINT 'Scripting.FileSystemObject : ' 

--Delete a file 
execute @OLEResult = sp_OAMethod @FS, 'DeleteFile', NULL, @FileName 
IF @OLEResult <> 0 exec DisplayOAErrorInfo @FS,@OLEResult 

EXECUTE @OLEResult = sp_OADestroy @FileID 
EXECUTE @OLEResult = sp_OADestroy @FS 
